// 云函数入口文件
const cloud = require('wx-server-sdk');
//将xml转化为json包
const xml2js = require('xml2js');
//http访问包
var superagent = require('superagent');
//md5加密包
var md5 = require('md5-node');
//requset包
const request = require('request')

//安装xml向json的转化包

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

//*******************************【配置】****************************
const config={
  BODY:'伐木累-炒酸奶', //商品类型信息
  MCHID:'1513477211', //商户id
  ENV_ID: 'data-0b70e3', // 环境名称
  FUNC_NAME: 'payCallBack', // 支付成功回调云函数
};

//*****************************************************************************

// 云函数入口函数
exports.main = async (event, context) => {

  let openid = event.userInfo.openId; // openid
  let totalFee = event.totalFee; //传入总价
  let outTradeNo = event.outTradeNo; //传入订单号

  const res = await cloud.cloudPay.unifiedOrder({
    "body" : config.BODY,
    "outTradeNo" : outTradeNo,
    "spbillCreateIp" : "127.0.0.1",
    "subMchId" : config.MCHID,
    "totalFee" : totalFee,
    "envId": config.ENV_ID,
    "functionName": config.FUNC_NAME
  })

  return res
   
}